package com.ibiaoke.goods.service;

import com.ibiaoke.common.base.Page;
import com.ibiaoke.common.utils.AssertUtils;
import com.ibiaoke.goods.dao.XcxGoodsDao;
import com.ibiaoke.goods.entity.XcxGoods;
import com.ibiaoke.goods.entity.vo.XcxGoodsVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class XcxGoodsServiceImpl implements XcxGoodsService{
    @Autowired
    private XcxGoodsDao xcxGoodsDao;

    @Override
    public List<XcxGoods> xcxListGoodsByGoodsClass(Integer cateId, Integer shopId, Page page) {
        return xcxGoodsDao.xcxListGoodsByGoodsClass(cateId,shopId,page);
    }

    @Override
    public XcxGoods getXcxGoodsByGoodsId(Integer goodsId, Integer shopId) {
        return xcxGoodsDao.getXcxGoodsByGoodsId(goodsId,shopId);

    }

    @Override
    public XcxGoods getXcxGoodsById(Integer goodsId) {
        return xcxGoodsDao.selectByPrimaryKey(goodsId);
    }

    @Override
    public List<XcxGoods> listXcxGoods(XcxGoodsVO xcxGoodsVO, Page page) {

        return xcxGoodsDao.listXcxGoods(xcxGoodsVO,page);
    }

    @Override
    public int saveXcxGoods(XcxGoods xcxGoods) {
        AssertUtils.notBlank(xcxGoods.getName(), "商品名称不能为空");
        AssertUtils.notNull(xcxGoods.getCateId(), "商品分类不能为空");
        AssertUtils.notNull(xcxGoods.getTag(), "商品标签不能为空");
        AssertUtils.notNull(xcxGoods.getSpec(), "商品规格不能为空");
        AssertUtils.notNull(xcxGoods.getStockNum(), "商品库存不能为空");
        AssertUtils.notNull(xcxGoods.getStatus(), "商品上下架状态不能为空");
        AssertUtils.notBlank(xcxGoods.getImage(),"商品主图不能为空");
        AssertUtils.notBlank(xcxGoods.getThumImage(),"商品缩略图不能为空");

        xcxGoods.setCreateTime(new Date());
        xcxGoods.setUpdateTime(new Date());
        return xcxGoodsDao.insertSelective(xcxGoods);
    }

    @Override
    public int batchUpdateGoodsStatus(String xcxGoodsId, Integer status) {
        AssertUtils.notBlank(xcxGoodsId,"商品Id不能为空");
        return xcxGoodsDao.batchUpdateGoodsStatus(xcxGoodsId,status);
    }

    @Override
    public int batchUpdateGoodsDelStatus(String xcxGoodsId, Integer delStatus) {
        AssertUtils.notBlank(xcxGoodsId,"商品Id不能为空");
        return xcxGoodsDao.batchUpdateGoodsDelStatus(xcxGoodsId,delStatus);
    }

    @Override
    public int updateGoodsInfoById(XcxGoodsVO xcxGoodsVO) {
        AssertUtils.notNull(xcxGoodsVO.getGoodsId(),"商品Id不能为空");
        return xcxGoodsDao.updateGoodsInfoById(xcxGoodsVO);
    }
}
